set ns [new Simulator]

#Define different colors for data flows (for NAM)
$ns color 1 Blue
$ns color 2 Red

#Open the Trace file
set file1 [open etrace.tr w]
$ns trace-all $file1

#Open the NAM trace file
set file2 [open etrace.nam w]
$ns namtrace-all $file2

#Define a 'finish' procedure
proc finish {} {
        global ns file1 file2
        $ns flush-trace
        close $file1
        close $file2
        exec nam ptrace.nam &
        exit 0
}

#Next line should be commented out to have the static routing
$ns rtproto DV

#Creat network nodes
#n0 represents the Internet
set n(0) [$ns node]
set n(1) [$ns node]
set n(2) [$ns node]
set n(3) [$ns node]
set n(4) [$ns node]
set n(5) [$ns node]
set n(6) [$ns node]
set n(7) [$ns node]
set n(8) [$ns node]
set n(9) [$ns node]
set n(10) [$ns node]
set n(11) [$ns node]
$n(11) shape "box"
set n(12) [$ns node]
$n(12) shape "box"
set n(13) [$ns node]
$n(13) shape "box"
set n(14) [$ns node]
$n(14) shape "box"
set n(15) [$ns node]
$n(15) shape "box"
set n(16) [$ns node]
$n(16) shape "box"
set n(17) [$ns node]
$n(17) shape "box"
set n(18) [$ns node]
$n(18) shape "box"
set n(19) [$ns node]
$n(19) shape "box"
set n(20) [$ns node]
$n(20) shape "box"
set n(21) [$ns node]
$n(21) shape "box"
set n(22) [$ns node]
$n(22) shape "box"
set n(23) [$ns node]
$n(23) shape "box"
set n(24) [$ns node]
$n(24) shape "box"
set n(25) [$ns node]
$n(25) shape "box"

#Create duplex links between the nodes
$ns duplex-link $n(0) $n(1) 100Mb 10ms DropTail
$ns duplex-link $n(0) $n(2) 100Mb 10ms DropTail
$ns duplex-link $n(0) $n(3) 100Mb 10ms DropTail
$ns duplex-link $n(0) $n(10) 100Mb 10ms DropTail

$ns duplex-link $n(1) $n(4) 100Mb 10ms DropTail
$ns duplex-link $n(1) $n(5) 100Mb 10ms DropTail
$ns duplex-link $n(2) $n(4) 100Mb 10ms DropTail
$ns duplex-link $n(2) $n(5) 100Mb 10ms DropTail

$ns duplex-link $n(4) $n(6) 100Mb 10ms DropTail
$ns duplex-link $n(4) $n(7) 100Mb 10ms DropTail
$ns duplex-link $n(4) $n(8) 100Mb 10ms DropTail
$ns duplex-link $n(4) $n(9) 100Mb 10ms DropTail

$ns duplex-link $n(5) $n(11) 100Mb 10ms DropTail
$ns duplex-link $n(5) $n(12) 100Mb 10ms DropTail
$ns duplex-link $n(5) $n(13) 100Mb 10ms DropTail
$ns duplex-link $n(5) $n(14) 100Mb 10ms DropTail

$ns duplex-link $n(6) $n(15) 100Mb 10ms DropTail
$ns duplex-link $n(6) $n(16) 100Mb 10ms DropTail

$ns duplex-link $n(8) $n(17) 100Mb 10ms DropTail
$ns duplex-link $n(8) $n(18) 100Mb 10ms DropTail

$ns duplex-link $n(9) $n(19) 100Mb 10ms DropTail
$ns duplex-link $n(9) $n(20) 100Mb 10ms DropTail

$ns duplex-link $n(7) $n(21) 100Mb 10ms DropTail
$ns duplex-link $n(7) $n(22) 100Mb 10ms DropTail
$ns duplex-link $n(7) $n(23) 100Mb 10ms DropTail

$ns duplex-link $n(3) $n(24) 100Mb 10ms DropTail

$ns duplex-link $n(10) $n(25) 100Mb 10ms DropTail

#Setup TCP connections for normal traffic
set numSrc 25
for {set i 12} {$i <= $numSrc} {incr i} {
    set src($i) [new Agent/TCP]
}

#setup sinks
#set numSinks 15
#for {set i 1} {$i <= $numSinks} {incr i} {
    set sink(1) [new Agent/TCPSink]
#}

#attaching TCP src to the victim nodes
set numSrcs 25
for {set i 12} {$i <= $numSrcs} {incr i} {
    $n($i) attach $src($i) 7771
}

#attaching TCP sink to n(11)
$n(11) attach $sink(1) 21

#Listen for sink at n(11)
$sink(1)  listen;

#Connect for all probes
set numProbes 25
for {set i 12} {$i <= $numProbes} {incr i} {
    $ns connect $src($i) $sink(1)
}

#Setup FTP applications to simulate traffic over TCP connections
set numFTPAgents 25
for {set i 12} {$i <= $numFTPAgents} {incr i} {
    set ftp($i) [new Application/FTP]
    $ftp($i) attach-agent $src($i)
}

proc traffic {app start_time stop_time} {
    global ns
    $ns at $start_time "$app start"
    $ns at $stop_time "$app stop"
}

#Start simulation
set numProbeSes 25
for {set i 12} {$i <= $numProbeSes} {incr i} {
    traffic $ftp($i) 0.1 1.1
}

$ns at 1.2 "finish"

$ns run

